﻿#region Using Statements
using GameBase.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace StarFox.ScreenComponents
{
    /// <summary>
    /// Implementation of a head-up display.
    /// <para>Definition of Draw() method.</para>
    /// </summary>
    partial class HeadUpDisplay
    {
        /// <summary>
        /// Called when the ScreenComponent2D needs to be drawn.
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to this method.</param>
        public override void Draw(GameTime gameTime)
        {
            if (!Visible)
                return;

            Rectangle auxRect;

            #region Bombs, Fuel, Health, Boost

            for (int i = 0; i < Bombs; i++)
            {
                Rectangle auxDstRectBomb = dstRectBomb;
                auxDstRectBomb.X += distToBomb * i;
                SpriteBatch.Draw(spriteSheet.Texture, auxDstRectBomb, spriteSheet.SourceRectangle("ICON_BOMB"), Color.Red);
            }

            // HUD - Fuel
            SpriteBatch.Draw(spriteSheet.Texture, dstRectFuel, spriteSheet.SourceRectangle("BAR_FUEL"), Color.Red);
            // HUD - Fuel Percent
            SpriteBatch.DrawString(smallFont, fuelPercentText,
                                   new Vector2(dstRectFuel.X + posFuelPercent.X, dstRectFuel.Y + posFuelPercent.Y),
                                   Color.Yellow, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            // HUD - Fuel Bar
            fuelBar.X = dstRectFuel.X;
            fuelBar.Draw();

            // HUD - Health
            SpriteBatch.Draw(spriteSheet.Texture, dstRectHealth, spriteSheet.SourceRectangle("BAR_HEALTH"), Color.Red);
            // HUD - Health Bar
            healthBar.X = dstRectHealth.X;
            healthBar.Draw();

            // HUD - Boost Bar
            boostBar.X = dstRectBoost.X;
            boostBar.Draw();
            // HUD - Boost
            SpriteBatch.Draw(spriteSheet.Texture, dstRectBoost, spriteSheet.SourceRectangle("BAR_BOOST"), Color.Red);

            #endregion

            #region Lives, Score, Time, Position, Speed

            SpriteBatch.DrawString(smallFont, "LIVES", posLives, Color.Red, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.DrawString(smallFont, "+" + livesText, new Vector2(posLives.X + distToLives, posLives.Y), Color.Yellow, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);

            SpriteBatch.DrawString(smallFont, "SCORE ", posScore, Color.Red, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.DrawString(smallFont, "+" + scoreText, new Vector2(posScore.X + distToScore, posScore.Y), Color.Yellow, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);

            SpriteBatch.DrawString(smallFont, "POS ", new Vector2(posScore.X, posScore.Y + distToPosition), Color.Red, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.DrawString(smallFont, positionText, new Vector2(posScore.X + distToScore, posScore.Y + distToPosition), Color.Yellow, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);

            SpriteBatch.DrawString(smallFont, "TIME ", new Vector2(posScore.X, posScore.Y + distToTime), Color.Red, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.DrawString(smallFont, timeText, new Vector2(posScore.X + distToScore, posScore.Y + distToTime), Color.Yellow, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);

            SpriteBatch.DrawString(smallFont, "SPEED ", new Vector2(posScore.X, posScore.Y + distToSpeed), Color.Red, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.DrawString(smallFont, speedText, new Vector2(posScore.X + distToScore, posScore.Y + distToSpeed), Color.Aqua, 0, Vector2.Zero, Screen.Scale, SpriteEffects.None, 0);

            #endregion

            #region Cross Hair

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_TARGET");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_RETICLE");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair, auxRect, Color.Red,
                             crossHairAngle, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_BAR_BOTTOM_LEFT");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair_Bar_Bottom_Left, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, 0), Screen.Scale, SpriteEffects.None, 0);

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_BAR_BOTTOM_RIGHT");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair_Bar_Bottom_Right, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, 0), Screen.Scale, SpriteEffects.None, 0);

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_BAR_TOP_LEFT");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair_Bar_Top_Left, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, auxRect.Height), Screen.Scale, SpriteEffects.None, 0);

            auxRect = spriteSheet.SourceRectangle("CROSSHAIR_BAR_TOP_RIGHT");
            SpriteBatch.Draw(spriteSheet.Texture, posCrossHair_Bar_Top_Right, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, auxRect.Height), Screen.Scale, SpriteEffects.None, 0);

            #endregion

            #region Collisions

            if (!toVisible && !toHidden)
            {
                if (isDanger_Left)
                {
                    auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_LEFT");
                    SpriteBatch.Draw(spriteSheet.Texture, dstRectDanger_Left, auxRect, Color.Red * dangerAlpha_Left);
                }

                if (isDanger_Center)
                {
                    auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_CENTER");
                    SpriteBatch.Draw(spriteSheet.Texture, dstRectDanger_Center, auxRect, Color.Red * dangerAlpha_Center);
                }

                if (isDanger_Right)
                {
                    auxRect = spriteSheet.SourceRectangle("ARROW_DANGER_RIGHT");
                    SpriteBatch.Draw(spriteSheet.Texture, dstRectDanger_Right, auxRect, Color.Red * dangerAlpha_Right);
                }
            }

            #endregion

            #region Ship

            // HUD - Ship
            auxRect = spriteSheet.SourceRectangle("SHIP_CENTER");
            SpriteBatch.Draw(spriteSheet.Texture, posShip, auxRect, Color.Red,
                             shipAngle, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);
            auxRect = spriteSheet.SourceRectangle("SHIP_LEFT");
            SpriteBatch.Draw(spriteSheet.Texture, posShip, auxRect, Color.Red,
                             shipAngle, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);
            auxRect = spriteSheet.SourceRectangle("SHIP_RIGHT");
            SpriteBatch.Draw(spriteSheet.Texture, posShip, auxRect, Color.Red,
                             shipAngle, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);

            // HUD - Circle
            auxRect = spriteSheet.SourceRectangle("SHIP_CIRCLE");
            SpriteBatch.Draw(spriteSheet.Texture, posShip, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);

            // HUD - Squares
            auxRect = spriteSheet.SourceRectangle("SQUARE_VER");
            SpriteBatch.Draw(spriteSheet.Texture, posSqr_Left, auxRect, Color.Red,
                             0.0f, new Vector2(0.0f, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.Draw(spriteSheet.Texture, posSqr_Right, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width, auxRect.Height / 2), Screen.Scale, SpriteEffects.None, 0);
            auxRect = spriteSheet.SourceRectangle("SQUARE_HOR");
            SpriteBatch.Draw(spriteSheet.Texture, posSqr_Top, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, 0.0f), Screen.Scale, SpriteEffects.None, 0);
            SpriteBatch.Draw(spriteSheet.Texture, posSqr_Bottom, auxRect, Color.Red,
                             0.0f, new Vector2(auxRect.Width / 2, auxRect.Height), Screen.Scale, SpriteEffects.None, 0);

            #endregion

            #region Bomb Mode

            if (isBombMode) { bombModeBar.Draw(); }

            #endregion
        }
    }
}
